#ifndef HASH_H
#define HASH_H
#include "storage.h"
#include <stdbool.h>

// @note: Must always define smallest element at top of header file,
//        similar to how you define function headers before main function
// This is the data structure for each table
// @note Each table is created at the beginning when config file is read

struct Record
{
    char name[MAX_KEY_LEN+1]; // This record's key (must be unique within a table)
    char value[MAX_VALUE_LEN+1]; // This record's value
    struct Record* left; // left child
    struct Record* right; // right child
    unsigned height; // height of this record node
};

// Implemented with an AVL tree
struct Table
{
    char name[MAX_TABLE_LEN+1];
    struct Record* head;
    int numRecs; // has to be less than MAX_RECORDS_PER_TABLE
};

static struct sortedArrayTable
{
    struct Table table[MAX_TABLES];
    int numTables; // has to be less than MAX_TABLES
} topTable;

// defined in utils.c
void initializeSortedArrayTable();
int insertTable(char* tname);
int sortTable();
void printTableName();
int findTableName(char* tname);
int insertRecord( struct Table *table, char* Key, char* Value);
int insertValue(char* Table, char* Key, char* Value);
// Record functions
void printRecord(int t_index);
int deleteRecord(char* name, int t_index);
int updateRecord(char* name, char* value, int t_index);
void getRecord(char* Table, char* Key, char* Value, int t_index);
int getValue(char* Table, char* Key, char* Value);
struct Record* createRecord(char* name, char* value);
int findTableIndex(char* tname);


// TODO: For milestone 3, EACH TABLE CAN HAVE MULTIPLE RECORDS
// Extended storage server constants.

#endif
